import { Node, Relationship } from "./tech-insight";

export interface ChatMessage {
  loading?: boolean;
  conversationId?: string;
  messageId: string;
  role: 'user' | 'assistant';
  content: string;
  timestamp: string;
  references?: {
    graphData?: {
      nodes: Node[];
      relationships: Relationship[];
    };
    // 以下数据接口中暂无
    links?: {
      title: string;
      content: string;
      source: string;
    }[];
    tags?: string[];
  };
}

export interface ChatResponse {
  task_id: string;
  answer: string;
  messageId: string;
  conversation_id: string;
  content: string;
  created_at: string;
  metadata?: {
    retriever_resources?: {
      position: string;
      dataset_id: string;
      dataset_name: string;
      document_id: string;
      document_name: string;
      segment_id: string;
      score: number;
      content: string;
    }[];
    usage?: {
      prompt_tokens: number;
      completion_tokens: number;
      total_tokens: number;
    };
  };
}

export interface ChatHistoryResponse {
  total: number;
  list: ChatMessage[];
}

export interface HistoryConversation {
  created_at: string;
  id: string;
  inputs: Record<string, any>;
  introduction: string;
  name: string;
  status: string;
  updated_at: string;
  messages?: HistoryMessage[];
}

export interface HistoryMessage {
  agent_thoughts: [];
  answer: string;
  conversation_id: string;
  created_at: number;
  error: string | null;
  feedback: string | null;
  id: string;
  inputs: {};
  message_files: [];
  parent_message_id: string;
  query: string;
  retriever_resources: [];
  status: string;
}

export interface ChatConversationsResponse {
  limit: number;
  has_more: boolean;
  data: HistoryConversation[];
}

export interface ChatMessagesResponse {
  limit: number;
  has_more: boolean;
  data: HistoryMessage[];
}

export interface SendMessageParams {
  query: string; // 用户输入/提问内容。
  inputs: Record<string, any>; // 输入参数，用于提供额外的背景信息。
  response_mode: 'streaming' | 'blocking'; // streaming 流式模式（推荐）。基于 SSE（Server-Sent Events）实现类似打字机输出方式的流式返回。 blocking 阻塞模式，等待执行完毕后返回结果。（请求若流程较长可能会被中断）。 由于 Cloudflare 限制，请求会在 100 秒超时无返回后中断。
  user: string; // 用户标识，用于定义终端用户的身份，方便检索、统计。 由开发者定义规则，需保证用户标识在应用内唯一。
  conversation_id?: string; // 会话 ID，需要基于之前的聊天记录继续对话，必须传之前消息的 conversation_id。
}

export interface GetConversationsParams {
  limit: number;
  user: string;
  last_id?: string | null;
};

export interface GetConversationMessagesParams {
  conversation_id: string;
  limit: number;
  user: string;
  first_id?: string | null;
}
